package com.dl.study.factory;

import com.dl.study.bean.Page;
import com.dl.study.bean.WrappedProcessInstanceBean;
import org.activiti.engine.runtime.ProcessInstance;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * create by chongyahhh
 * 2020/4/4
 */
public class ProcessInstanceBeanWrappedFactory {

    public static WrappedProcessInstanceBean inject(ProcessInstance var){
        return new WrappedProcessInstanceBean(var.getId(),var.getName(),var.getDescription(),var.getProcessDefinitionId(),
                var.getStartTime(),var.getProcessDefinitionKey(),var.getBusinessKey(),var.isSuspended());
    }

    public static List<WrappedProcessInstanceBean> inject(List<ProcessInstance> var){
        List<WrappedProcessInstanceBean> data = new ArrayList<>();
        Iterator iterator = var.iterator();
        ProcessInstance temp;
        while(iterator.hasNext()){
            temp = (ProcessInstance)iterator.next();
            data.add(new WrappedProcessInstanceBean(temp.getId(),temp.getName(),temp.getDescription(),temp.getProcessDefinitionId(),
                    temp.getStartTime(),temp.getProcessDefinitionKey(),temp.getBusinessKey(),temp.isSuspended()));
        }
        return data;
    }

    public static Page<List<WrappedProcessInstanceBean>> inject(List<ProcessInstance> var, Integer pageNum, Integer pageSize, Integer totalPage){
        Page<List<WrappedProcessInstanceBean>> page = new Page<>();
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        page.setTotalPage(totalPage);
        page.setData(inject(var));
        return page;
    }
}
